#include <REGX52.H>
#include "LCD1602.h"
#include "DS1302.h"
#include "PCF8591.h"
#include "Delay.h"
#include "UART.h"
#include "Timer0.h"



//引脚定义
sbit SW1=P1^0;
sbit SW2=P1^1;
sbit SW3=P1^2;
sbit SW4=P1^3;
sbit LED1=P1^4;
sbit LED2=P1^5;
sbit LED3=P1^6;
sbit LED4=P1^7;

//led switch程序
void Led_switch()
{
	if(SW1 == 0){LED1 = 0;}else{LED1 = 1;}
	if(SW2 == 0){LED2 = 0;}else{LED2 = 1;}
	if(SW3 == 0){LED3 = 0;}else{LED3 = 1;}
	if(SW4 == 0){LED4 = 0;}else{LED4 = 1;}
}

void TimeShow(void)//时间显示功能
{
	DS1302_ReadTime();//读取时间
	LCD_ShowNum(1,1,DS1302_Time[0],2);//显示年
	LCD_ShowNum(1,4,DS1302_Time[1],2);//显示月
	LCD_ShowNum(1,7,DS1302_Time[2],2);//显示日
	LCD_ShowNum(2,1,DS1302_Time[3],2);//显示时
	LCD_ShowNum(2,4,DS1302_Time[4],2);//显示分
	LCD_ShowNum(2,7,DS1302_Time[5],2);//显示秒
}

int main()
{
	LCD_Init();
	DS1302_Init();
	UART_Init();
	Timer0Init();
	LCD_ShowString(1,1,"  -  -  ");//静态字符初始化显示
	LCD_ShowString(2,1,"  :  :  ");	
	while(1)
	{
		Get_number();
		TimeShow();
		Led_switch();	
	}
}


void Timer0_Routine() interrupt 1
{
	static unsigned int T0Count;
	unsigned char num;
	TL0 = 0x18;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	T0Count++;
	if(T0Count>=1000)
	{
		T0Count=0;
		for(num = 0;num<6;num++)
		{
			UART_SendByte(DS1302_Time[num]);
		}
		
		
	}
}

